package com.rentalHome.controller;

import com.rentalHome.domain.Rental;
import com.rentalHome.domain.Room;
import com.rentalHome.domain.User;
import com.rentalHome.repository.PaymentRepository;
import com.rentalHome.repository.RentalRepository;
import com.rentalHome.repository.RoomRepository;
import com.rentalHome.repository.UserRepository;
import com.rentalHome.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by LeeXyan on 2017/02/19.
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private PaymentRepository paymentRepository;

    @Autowired
    private RoomRepository roomRepository;

    @Autowired
    private RentalRepository rentalRepository;

    @GetMapping("/list")
    public ResponseEntity paymentList(@RequestParam("userId")Long userId,@RequestParam("roomNum")String roomNum,@RequestParam("customerName")String customerName){
        User user=userRepository.findOne(userId);
        Room room=roomRepository.findByName(roomNum);
        Rental rental=rentalRepository.findByCustomerName(customerName);
        return ResponseEntity.ok( paymentRepository.findByUserAndRentalAndRoom(user,rental,room));
    }

}
